package com.ny.dao.impl;

import com.ny.dao.OrderDao;
import com.ny.entity.Order;
import com.ny.until.DbUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class OrderDaoImpl implements OrderDao {
    private DbUtil dbUtil=new DbUtil();
    @Override
    public int insertOrder(Order order) throws SQLException {

        Connection connection = dbUtil.getCon();
        String sql = "INSERT INTO orders(studentId,productId,number,totalPrice) VALUES ( ?, ?, ?, ?);";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setInt(1,order.getStudentId());
        preparedStatement.setInt(2,order.getProductId());
        preparedStatement.setInt(3,order.getNumber());
        preparedStatement.setDouble(4,order.getTotalPrice());
        return preparedStatement.executeUpdate();
    }
}
